package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.pojo.Courier;
import com.sky.pojo.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理端：订单控制器层
 * @author zgp
 * @version V1.0
 * @date 2025-02-07 8:55
 */
@Slf4j
@Api(tags = "订单管理接口")
@RestController("adminOrdersController")
@RequestMapping("/admin/order")
public class OrdersController {
    @Autowired
    private OrderService orderService;

    @ApiOperation("订单条件查询接口")
    @GetMapping("/conditionSearch")
    public Result<PageResult<OrderVO>> conditionSearchOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单条件查询接口：ordersPageQueryDTO = {}", ordersPageQueryDTO);
        return Result.success(orderService.conditionSearchOrders(ordersPageQueryDTO));
    }

    @ApiOperation("各状态订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> orderStatistics(){
        log.info("各状态订单数量统计");
        return Result.success(orderService.orderStatistics());
    }

    @ApiOperation("订单详情查看")
    @GetMapping("/details/{id}")
    public Result<Orders> getOrderAndDetails(@PathVariable Long id){
        log.info("订单详情查看：id = {}", id);
        return Result.success(orderService.getOrdersDetail(id));
    }

    @ApiOperation("商家拒单")
    @PutMapping("/rejection")
    public Result<String> rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("商家拒单：ordersRejectionDTO = {}", ordersRejectionDTO);
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result<String> cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单：ordersCancelDTO = {}", ordersCancelDTO);
        orderService.cancelOrders(ordersCancelDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @ApiOperation("商家接单")
    @PutMapping("/confirm")
    public Result<Courier> confirmOrders(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("商家接单：ordersConfirmDTO = {}", ordersConfirmDTO);
        return Result.success(orderService.confirmOrders(ordersConfirmDTO));
    }

}
